<script type="text/javascript"><!--//--><![CDATA[//><!--

	var grid_reload = function(){
		$('#datagrid').datagrid('reload', $('#fm_search').serializeObject());
	};

	$(document).ready(function() {

		// Setup Datagrid
		$('#datagrid').datagrid({  
			url:gs_path+'/'+controller+'/getdata', 
			queryParams: $('#fm_search').serializeObject(),
			height:340,
			pagination:true,
			columns:[[
				{ field : 'ck', checkbox:true, width: 40, align: 'center' },
				{ field : 'kode_komplain', title : 'Kode Komplain', width : 180, sortable:true },
				// { field : 'nama', title : 'Nama', width : 120, sortable:true },
				{ field : 'tgl_komplain', title : 'Tanggal Komplain', width : 120, sortable:true },
				{ field : 'nama_departemen', title : 'Departemen', width : 300, sortable:true },
				{ field : 'komplain', title : 'Komplain', width : 300, sortable:true },
				{ field : 'status', title : 'Status', width : 130, sortable:true },
				//{ field : 'jenis_kebutuhan', title : 'Jenis Kebutuhan', width : 150, sortable:true },
				//{ field : 'jenis_permintaan', title : 'Jenis Permintaan', width : 170, sortable:true },
				{ field : 'tanggal_selesai', title : 'Tanggal Selesai', width : 120, sortable:true },
				{ field : 'keterangan', title : 'Keterangan', width : 250, sortable:true }
			]]
		});		
		
		// Setup Form
		$('#form_master').setupForm([			
			{ name: 'kode_komplain', type: 'text', size: 'medium', maxlength: 50, noempty:true },
			{ name: 'tgl_komplain', type: 'date', noempty:true },
			{ name: 'nama_unit', type:'lov', data: <?php echo json_encode($unitkerja); ?>, size: 'long', noempty:true },
			{ name: 'komplain', type: 'textarea', size:'long', rows:3 , noempty:true },
			{ name: 'status', type:'lov', data: <?php echo json_encode($arr_customer2); ?>, size: 'medium', noempty:true },			
			{ name: 'keterangan', type: 'textarea', size:'long', rows:3 },
			{ name: 'tanggal_selesai', type: 'date' },
			{ name: 'atas_nama', type: 'text', size: 'long', maxlength: 60, noempty:true },
		]);
		
		
		// Create Dialog
		$('#dialog_container').dialog({
			closed:true,
			modal:true,
			title: '_',
			width:500,
			height:550,
			buttons:[{
				text:'Save',
				iconCls:'icon-save',
				handler:function(){
					hardware = ($('#hardware')[0].checked == true) ? $('#hardware')[0].value : '';
                    software = ($('#software')[0].checked == true) ? $('#software')[0].value : '';
                    database = ($('#database')[0].checked == true) ? $('#database')[0].value : '';
                    lan = ($('#lan')[0].checked == true) ? $('#lan')[0].value : '';

                    jenis_kebutuhan = hardware+','+software+','+database+','+lan;
                    $('#jenis_kebutuhan').setval(jenis_kebutuhan);

                    aplikasi = ($('#aplikasi')[0].checked == true) ? $('#aplikasi')[0].value : '';
                    penambahan_pengadaan_baru = ($('#penambahan_pengadaan_baru')[0].checked == true) ? $('#penambahan_pengadaan_baru')[0].value : '';
                    technical_support = ($('#technical_support')[0].checked == true) ? $('#technical_support')[0].value : '';

                    jenis_permintaan = aplikasi+','+penambahan_pengadaan_baru+','+technical_support;
                    $('#jenis_permintaan').setval(jenis_permintaan);

					$('#form_master').submitForm('/'+controller+'/ajax_post', { onComplete : function(){ $('#dialog_container').dialog('close'); $('#datagrid').datagrid('reload'); }} );
					//loadPage(gs_path + '/' + controller + '/index/');
				}
			},{
				text:'Close',
				iconCls:'icon-cancel',
				handler:function(){
					$('#dialog_container').dialog('close');
				}
			}]
		});
		
		
		// Set Action Button
		var buttons = [ { label: 'Add', icon: 'add', onclick: function() {
							resetError();
							$.ajax({
								url:gs_path+'/'+controller+'/id_auto',
								type:'POST',
								dataType:'JSON',
								}).done(function(data){
									$('#id_komplain').setval(data['id_komplain_auto']);
									$('#kode_komplain').setval(data['kode_komplain_auto']);
							});
							$('#dialog_container').dialog('open');
							$('#form_master').data('mode', 'create');
							$('#form_master').parent().parent().parent().prev().find('.panel-title').html('New Komplain');
							//$('#kode_komplain').readonly(false);
							$('#kode_komplain, #tgl_komplain, #nama_unit, #komplain, #status, #keterangan').val('');
							$('#kode_komplain').focus();
						} },
						{ label: 'Edit', icon: 'edit', onclick: function() {
							var oSel=$('#datagrid').datagrid('getSelected'); 
							if(oSel==null){ alert('Please select row!'); }
							else{ 

								var jenis_kebutuhan = oSel.jenis_kebutuhan;
								var jenis_permintaan = oSel.jenis_permintaan;
								$.ajax({
									url: gs_path+'/'+controller+'/edit_checkbox',
									type: 'POST',
									dataType:'json',
									data: { jenis_kebutuhan : jenis_kebutuhan , jenis_permintaan : jenis_permintaan},
								}).done(function(data){

									//alert(data.kebutuhan[0]);

									if(data.kebutuhan[0]!=""){
										document.getElementById('hardware').checked = true;
									} else {
										document.getElementById('hardware').checked = false;
									}

									if(data.kebutuhan[1]!=""){
										document.getElementById('software').checked = true;
									} else {
										document.getElementById('software').checked = false;
									}

									if(data.kebutuhan[2]!=""){
										document.getElementById('database').checked = true;
									} else {
										document.getElementById('database').checked = false;
									}

									if(data.kebutuhan[3]!=""){
										document.getElementById('lan').checked = true;
									} else {
										document.getElementById('lan').checked = false;
									}


									if(data.permintaan[0]!=""){
										document.getElementById('aplikasi').checked = true;
									} else {
										document.getElementById('aplikasi').checked = false;
									}

									if(data.permintaan[1]!=""){
										document.getElementById('penambahan_pengadaan_baru').checked = true;
									} else {
										document.getElementById('penambahan_pengadaan_baru').checked = false;
									}

									if(data.permintaan[2]!=""){
										document.getElementById('technical_support').checked = true;
									} else {
										document.getElementById('technical_support').checked = false;
									}

								});

								resetError();
								$('#dialog_container').dialog('open'); 
								$('#form_master').data('mode', 'edit');
								$('#form_master').parent().parent().parent().prev().find('.panel-title').html('Edit Komplain');
								$('#kode_komplain').readonly(true);
								jsonToForm(oSel); $('#tgl_komplain').focus();
								$('#id_komplain').setval(oSel['id_komplain']);
							} 
						}},
						{label: 'Delete', icon: 'delete', onclick: function() { 
							var oSel = $('#datagrid').datagrid('getSelected'); 
							if (oSel == null) { 
								$.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
							} else { 
								deleteData(['id_komplain']);
							} 
						}}];
		setAction(buttons);
		
		
		$('#fm_search').focusFirst();

	

	});
//--><!]]></script>

<div id="tb" style="padding:5px;height:auto">
    <div>
        <form id="fm_search" onsubmit="grid_reload(); return false;">
        	<table class="tb_form" style="margin-bottom:0px">
            <tr>
            	<td width="100">Keyword</td>
                <td><input type="text" id="keyword" name="keyword" class="textfield medium" />
                	<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="grid_reload(); return false;">Search</a>
                </td>
            </tr>
            </table>
        </form>
    </div>
</div>
<div id="datagrid" toolbar="#tb"></div>


<div id="dialog_container" style="padding:5px;width:600px;height:380px;">
	<form id="form_master">
    <table class="tb_form" style="width:100%;" cellpadding="0" cellspacing="0">
    <tr>
        <td><input id="id_komplain" name="id_komplain" type="hidden"/></td>
    </tr>
    <tr>
        <td style="width:120px">Kode Komplain</td>
        <td><input id="kode_komplain" /></td>
    </tr>
    <tr>
        <td style="width:120px">Nama</td>
        <td><input id="atas_nama" /></td>
    </tr>
    <tr>
        <td style="width:120px">Departemen</td>
        <td><input id="nama_unit" /></td>
    </tr> 
    <tr>
        <td style="width:120px">Tanggal Komplain</td>
        <td><input id="tgl_komplain" /></td>
    </tr>
    </table>
    <table>
    	<tr>
    		<td style="width:150px" colspan="4"><b>Jenis Kebutuhan :</b> <input type="hidden" name="jenis_kebutuhan" id="jenis_kebutuhan" /></td>
    	</tr>
    	<tr>
    		<td style="width:100px"><input type="checkbox" id="hardware" value="hardware">Hardware</td>
    		<td style="width:100px"><input type="checkbox" id="software" value="software">Software</td>
    		<td style="width:100px"><input type="checkbox" id="database" value="database">Database</td>
    		<td style="width:100px"><input type="checkbox" id="lan" value="lan">LAN</td>
    	</tr>
    </table>
    <table>
    	<tr>
    	<td style="width:150px" colspan="3"><b>Jenis Permintaan :</b> <input type="hidden" name="jenis_permintaan" id="jenis_permintaan" /></td>
    	</tr>
    	<tr>
    		<td style="width:80px"><input type="checkbox" id="aplikasi" value="aplikasi">Aplikasi</td>
    		<td style="width:5px"><input type="checkbox" id="penambahan_pengadaan_baru" value="penambahan_pengadaan_baru"></td style="width:100px"><td>Penambahan/Pengadaan Baru</td>
    		<td style="width:5px"><input type="checkbox" id="technical_support" value="technical_support"></td><td style="width:150px">Technical Support/Trouble Shooting</td>
    	</tr>
    </table>
    <table>
    	<tr>
    		<td  colspan="2" style="width:100px">Uraian permohonan atau masalah yang terjadi :</td>
    	</tr>
    	<tr>
    		<td  colspan="2"><input id="komplain"/></td>
    	</tr>
    	<tr>
    		<td style="width:100px">Status :</td>
    		<td><input id="status" /></td>
    	</tr> 
    	<tr>
    		<td style="width:100px">Solusi :</td>
    	</tr> 
    	<tr>
    		<td colspan="2"><input id="keterangan" /></td>
    	</tr>
    </table>
    <table>                
    	<tr>
    		<td style="width:120px">Tanggal Selesai :</td>
    		<td>
    			<input id="tanggal_selesai" />
    		</td>
    	</tr>
    </table>
	</form>
</div>